package Year22_Month07.day03;

import java.util.LinkedList;
import java.util.List;

public class 递增子序列 {
    List<List<Integer>> resList = new LinkedList<>();
    List<Integer> list = new LinkedList<>();

    public List<List<Integer>> findSubsequences(int[] nums) {
        backStack(nums,0);
        int index = 0;
        while(index < resList.size()){
            if(!judge(list)){
                resList.remove(index);
            }else{
                index++;
            }
        }
        return resList;
    }

    public void backStack(int[] nums,int startIndex){
        if(list.size() >= 2){
            resList.add(list);
        }
        for (int i = startIndex; i < nums.length; i++) {
            list.add(nums[i]);
            backStack(nums,i + 1);
            list.remove(list.size() - 1);
        }
    }

    public boolean judge(List<Integer> list){
        for (int i = 1; i < list.size(); i++) {
            if(list.get(i) < list.get(i - 1)) return false;
        }
        return true;
    }
}
